/*
	Twitch
	Please leave credits to the origional devs where its due if edited.
*/

function GM:HUDPaint()
	local ply = LocalPlayer()
	if !ply or !ply:IsValid() then return end
	if !ply:GetShip():IsValid() then
		// Draw a respawn timer here or somethin'
		return
	end
	self:DrawShipData()
	self:DrawSpeed()
	if Debug then
		self:DrawDebug()
	end
end

function GM:DrawShipData()
	local MaxHealth = LocalPlayer():GetShip():MaxHealth()
	local Health = LocalPlayer():GetShip():Health()
	local MaxShield = LocalPlayer():GetShip():MaxShield()
	local Shield = LocalPlayer():GetShip():Shield()
	local MaxEnergy = LocalPlayer():GetShip():MaxEnergy()
	local Energy = LocalPlayer():GetShip():Energy()

	local Wide = 250 
	local Tall = 100 
	
	local X = 30
	local Y = ScrH() - Tall - 30
	
	draw.RoundedBox(6, X, Y, Wide, Tall, Color(0,0,0,150))
	
	X = X + 10
	Y = Y + 10
	
	Tall = 20
	Wide = Wide - 20

	// Health
	local Frac = math.Clamp(Health / MaxHealth,0,1)
	
	draw.RoundedBox(4, X - 3, Y - 3, Wide + 6, Tall + 6, Color(90,18,18,255))
	
	surface.SetDrawColor(180 ,16 ,29 ,255)
	surface.DrawRect(X,Y,Wide * Frac,Tall)
	
	draw.SimpleText(math.Round(Health), "Hud", X + 120, Y + 10 , Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
	
	
	// Shield
	Y = Y + 32
	
	Frac = math.Clamp(Shield / MaxShield,0,1)

	draw.RoundedBox(4, X - 3, Y - 3, Wide + 6, Tall + 6, Color(18,34,79,255))

	surface.SetDrawColor(73 ,98 ,166 ,255)
	surface.DrawRect(X,Y,Wide * Frac,Tall)

	draw.SimpleText(math.Round(Shield), "Hud", X + 120, Y + 10 , Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
	
	// Energy
	Y = Y + 32
	
	Frac = math.Clamp(Energy / MaxEnergy,0,1)

	draw.RoundedBox(4, X - 3, Y - 3, Wide + 6, Tall + 6, Color(179,142,41,255))

	surface.SetDrawColor(191 ,169 ,110 ,255)
	surface.DrawRect(X,Y,Wide * Frac,Tall)

	draw.SimpleText(math.Round(Energy), "Hud", X + 120, Y + 10 , Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
end

function GM:DrawSpeed()
	draw.SimpleText("Speed: "..LocalPlayer():GetShip():GetSpeed().." M/s","HudHud",ScrW()*0.5,ScrH()-50,Color(255,255,255,255),1)
end

function GM:DrawDebug()
	draw.SimpleText("Ship angle : "..tostring(LocalPlayer():GetNWString("TWC_ShipAngle")),"HudHud",ScrW()*0.5,ScrH()-100,Color(255,255,255,255),1)
	draw.SimpleText("Ship target angle : "..tostring(LocalPlayer():GetNWString("TWC_ShipTargetAngle")),"HudHud",ScrW()*0.5,ScrH()-75,Color(255,255,255,255),1)
end
